<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<link href="./css/merchant.css" rel="stylesheet" type="text/css" />
<script language="JavaScript"
	src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script>
<script language="JavaScript" src="./js/bootstrap.js"></script>
<script src="http://libs.baidu.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>

<link rel="stylesheet" type="text/css" href="./css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="./css/normalize.css" />
<link rel="stylesheet" type="text/css" href="./css/demo.css" />
<link rel="stylesheet" type="text/css" href="./css/icons.css" />
<link rel="stylesheet" type="text/css" href="./css/component.css" />
<link rel="stylesheet" type="text/css" href="./css/head.css" />
<link rel="stylesheet" type="text/css" href="./css/history_order.css" />
<script type="text/javascript">
	$(document).ready(function() {
		$("body").on("mouseenter", "tr", function() {
			$(this).css("background-color", "#efe2d2");
		});

		$("body").on("mouseleave", "tr", function() {
			$(this).css("background-color", "");
		});

	});
</script>
</head>
<body>
	<ul id="nav" class="hul">
		<img src="http://10.222.232.168:83/img/logo.png" />
		<li class="logout"><a href="logOut">注销</a></li>
		<li class="logout"><a href="orderManager.html" id="newMsg"></p></a></li>
	</ul>

	<div id="st-container" class="st-container">
		<nav class="st-menu st-effect-1" id="menu-1">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>

		<nav class="st-menu st-effect-2" id="menu-2">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>

		<nav class="st-menu st-effect-4" id="menu-4">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>

		<nav class="st-menu st-effect-5" id="menu-5">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>

		<nav class="st-menu st-effect-9" id="menu-9">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>

		<nav class="st-menu st-effect-10" id="menu-10">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>

		<nav class="st-menu st-effect-11" id="menu-11">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>

		<nav class="st-menu st-effect-12" id="menu-12">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>

		<nav class="st-menu st-effect-13" id="menu-13">
			<h2 class="icon icon-lab">商家</h2>
			<ul>
				<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
				<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
				<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
				<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
			</ul>
		</nav>


		<div class="st-pusher">
			<nav class="st-menu st-effect-3" id="menu-3">
				<h2 class="icon icon-lab">商家</h2>
				<ul>
					<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
					<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
					<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
					<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
				</ul>
			</nav>

			<nav class="st-menu st-effect-6" id="menu-6">
				<h2 class="icon icon-lab">商家</h2>
				<ul>
					<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
					<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
					<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
					<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
				</ul>
			</nav>

			<nav class="st-menu st-effect-7" id="menu-7">
				<h2 class="icon icon-lab">商家</h2>
				<ul>
					<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
					<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
					<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
					<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
				</ul>
			</nav>

			<nav class="st-menu st-effect-8" id="menu-8">
				<h2 class="icon icon-lab">商家</h2>
				<ul>
					<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
					<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
					<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
					<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
				</ul>
			</nav>

			<nav class="st-menu st-effect-14" id="menu-14">
				<h2 class="icon icon-lab">商家</h2>
				<ul>
					<li><a class="icon icon-data" href="dishManager.html">菜单管理</a></li>
					<li><a class="icon icon-study" href="orderManager.html">订单管理</a></li>
					<li><a class="icon icon-wallet" href="historyOrder.html">历史订单</a></li>
					<li><a class="icon icon-phone" href="merchentMsg.html">商家信息</a></li>
				</ul>
			</nav>
			<div class="st-content">

				<div class="st-content-inner">

					<div class="main clearfix">
						<div id="st-trigger-effects" class="column">

							<button data-effect="st-effect-8">商家管理</button>

						</div>
						<div class="dish">
							<div id="historyOrder"></div>


						</div>
					</div>
				</div>
			</div>

		</div>
		<script src="./js/classie.js"></script>
		<script src="./js/sidebarEffects.js"></script>
</body>

<script>
	$(document).ready(function() {

		$.ajax("loadHistoryOrder", {
			method : "GET",
			type : "json",
			success : function(result) {
				if (result) {
					if (result.history) {
						parseDish(result.history);
					}
				}
				;
			}
		});
	});
	function parseDish(data) {
		var notTake = document.getElementById("historyOrder");

		var tb = document.createElement("table");
		tb.setAttribute("class", "table table-hover");
		data.forEach(function(item, index, array) {
			var thead = document.createElement("thead");
			var tfoot = document.createElement("tfoot");
			var tbody = document.createElement("tbody");
			var dishes = JSON.parse(item.dishs);

			var tr1 = document.createElement("tr");
			var th1 = document.createElement("th");

			th1.innerHTML = "下单时间：" + item.orderTime;
			th1.setAttribute("colspan", "2");
			var th2 = document.createElement("th");
			th2.innerHTML = "购买者：" + item.user.account;
			var th3 = document.createElement("th");
			if (item.taken == 1) {
				th3.innerHTML = "状态：已接单";
			}
			;
			if (item.taken == -2) {
				th3.innerHTML = "状态：不接单";
			}
			if (item.taken == -1) {
				th3.innerHTML = "状态：已收货";
			}
			var th4 = document.createElement("th");
			th4.innerHTML = "总价：￥" + item.total;
			tr1.appendChild(th1);
			tr1.appendChild(th2);
			tr1.appendChild(th3);
			tr1.appendChild(th4);
			thead.appendChild(tr1);

			for (var j = 0; j < dishes.length; j++) {
				var tr2 = document.createElement("tr");
				var dtd1 = document.createElement("td");
				var dtd2 = document.createElement("td");
				var dtd3 = document.createElement("td");
				var dtd4 = document.createElement("td");
				var dtd5 = document.createElement("td");
				var img = document.createElement("img");
				img.setAttribute("src", dishes[j].dicon);
				img.setAttribute("width", "30");
				img.setAttribute("height", "30");
				dtd1.appendChild(img);

				dtd2.innerHTML = dishes[j].dname;
				dtd3.innerHTML = '￥' + dishes[j].price;

				dtd4.innerHTML = dishes[j].num;
				dtd5.innerHTML = '￥' + dishes[j].num * dishes[j].price;
				tr2.appendChild(dtd1);
				tr2.appendChild(dtd2);
				tr2.appendChild(dtd3);
				tr2.appendChild(dtd4);
				tr2.appendChild(dtd5);
				tbody.appendChild(tr2);
			}
			if (item.comments) {
				var tr3 = document.createElement("tr");
				var ftd1 = document.createElement("td");
				var ftd2 = document.createElement("td");
				ftd1.setAttribute("colspan", "4");
				ftd1.innerHTML = item.comments;
				ftd1.setAttribute("class", "comments");
				var but = document.createElement("button");
				but.innerHTML = "投诉进度";
				but.onclick = function() {
					processComments(item.oid);
				};
				but.setAttribute("id", item.oid);
				ftd2.appendChild(but);
				tr3.appendChild(ftd1);
				tr3.appendChild(ftd2);
				tbody.appendChild(tr3);
			}

			tb.appendChild(thead);
			tb.appendChild(tbody);
			tb.appendChild(tfoot);

		});
		notTake.appendChild(tb);
	}
	function processComments(oid) {
		data = {
			"oid" : oid
		};
		$.ajax("processComments", {
			method : "GET",
			type : "json",
			data : data,
			success : function(data) {
				console.log(data);
				var but = document.getElementById(oid);
				but.innerHTML = data.result;
			}
		});
	}
</script>
</html>
